package com.symaster.backups.repository;

import com.symaster.backups.model.FileSystemMonitorBackupItemModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * @author yinmiao
 * @version 2024/2/18
 */
@Repository
public interface FileSystemMonitorBackupItemRepository extends JpaRepository<FileSystemMonitorBackupItemModel, Integer> {

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent = ?3 and path_name = ?2", nativeQuery = true)
    List<FileSystemMonitorBackupItemModel> find(Integer fileSystemMonitorId, String pathName, Integer patent);

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent is null and path_name = ?2 ", nativeQuery = true)
    List<FileSystemMonitorBackupItemModel> find(Integer fileSystemMonitorId, String pathName);

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent = ?2", nativeQuery = true)
    List<FileSystemMonitorBackupItemModel> find(Integer fileSystemMonitorId, Integer patent);

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent is null", nativeQuery = true)
    List<FileSystemMonitorBackupItemModel> find(Integer fileSystemMonitorId);

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent = ?3 and path_name = ?2 and path_type = 2", nativeQuery = true)
    Optional<FileSystemMonitorBackupItemModel> findFolder(Integer fileSystemMonitorId, String pathName, Integer patent);

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent is null and path_name = ?2 and path_type = 2", nativeQuery = true)
    Optional<FileSystemMonitorBackupItemModel> findFolder(Integer fileSystemMonitorId, String pathName);

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent = ?2 and path_type = 2", nativeQuery = true)
    List<FileSystemMonitorBackupItemModel> findFolder(Integer fileSystemMonitorId, Integer patent);

    @Query(value = "select * from bk_file_system_monitor_backup_item where file_system_monitor_id = ?1 and patent is null and path_type = 2", nativeQuery = true)
    List<FileSystemMonitorBackupItemModel> findFolder(Integer fileSystemMonitorId);
}
